// import http from '@/utils/http';

export default {
  data() {
    return {
			formPath: '' as string,
			handing: false as boolean,
			formData: {}
    }
  },
	methods: {
		submit(){
			!this.handing && this.$refs.form.validate().then(() => {
				if (this.beforeSubmit()) {
					this.formData.id ? this.put() : this.post()
				} else {
          // console.log('验证失败');
				}
			}).catch(()=>{})
		},
		post(){
			this.handing = true
			usePost(this.formPath, this.formData).then((data: any) => {
				this.afterSubmit(data)
			}).finally(()=>{
				this.handing = false
			}).catch(() => {
			})
		},
		put(){
			this.handing = true
			usePut(this.formPath, this.formData).then((data: any) => {
				this.afterSubmit(data)
			}).finally(()=>{
				this.handing = false
			}).catch(() => {
			})
		},
		beforeSubmit(){
			return true;
		},
		afterSubmit(data: any){
		}
	}
}